package com.finance.rule.request;

import com.finance.base.constant.PatternConstants;
import com.finance.framework.lang.valid.EnumValid;
import com.finance.util.DateUtil;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.constraints.Pattern;
import java.text.ParseException;
import java.util.Date;

/**
 * Created by ljg on 2017/3/24.
 */
@Data
public class MixSectionImportReq {

    private String nickname;

    private String code;

    /**
     *供货商编码
     * */
    @Length(max=20,message = "供货商编码长度小于20")
    @NotBlank(message = "供货商不能为空或者不能有误")
    private String supplierCode;

    private String supplierCodeImport;

    /**
     *运单配送类型 枚举 0配送 1上门换 2上门退
     * */
    @NotBlank(message = "运单配送类型不能为空或者不能有误")
    private String direction;

    private String directionImport;

    /**
     *左边界数字
     * */
    @Length(max = 11,message = "左边界数字不能超过11位")
    @Pattern(regexp = PatternConstants.PATTERN_NUMBER_TWO_DECIMAL_POINT,message = "左边界数字最多两位小数")
    @NotBlank(message = "左边界数字不能为空")
    private String pointLeft;

    /**
     *是否包含边界数字 0表示值大于point_left 1表示值不小于point_left
     * */
    @EnumValid(enums = {"0","1"},message = "包含左边界数字枚举型")
    @NotBlank(message = "包含左边界数字不能为空")
    private String containLeft;

    private String containLeftImport;

    /**
     *右边界数字
     * */
    @Length(max = 11,message = "右边界数字不能超过11位")
    @Pattern(regexp = PatternConstants.PATTERN_NUMBER_TWO_DECIMAL_POINT,message = "右边界数字最多两位小数")
    @NotBlank(message = "右边界数字不能为空")
    private String pointRight;

    /**
     *是否包含边界数字 0表示值小于point_right 1表示值不大于point_right
     * */
    @EnumValid(enums = {"0","1"},message = "包含右边界数字枚举型")
    @NotBlank(message = "是否包含右边界不能为空或者不能有误")
    private String containRight;

    private String containRightImport;

    /**
     *结算类型 0投递员
     *        1合作站
     *        2合作商
     *        3大型合作商
     * */
    @NotBlank(message = "结算类型不能为空或者不能有误")
    private String settlementType;

    private String settlementTypeImport;

    private String fixWeight;

    /**
     *首件单价 单位元
     * */
    @Length(max = 11,message = "首重单价不能超过11位")
    @Pattern(regexp = PatternConstants.PATTERN_NUMBER_TWO_DECIMAL_POINT,message = "首重单价最多两位小数")
    @NotBlank(message = "首重单价不能为空")
    private String firstPiecePrice;


    /**
     *拖件单价 单位元
     * */
    @Length(max = 11,message = "首重单价不能超过11位")
    @Pattern(regexp = PatternConstants.PATTERN_NUMBER_TWO_DECIMAL_POINT,message = "首重单价最多两位小数")
    @NotBlank(message = "首重单价不能为空")
    private String secondPiecePrice;


    private String startTime;

    private String endTime;


    public Date convertStartTime() throws ParseException {
        if(this.startTime!=null){
            return DateUtil.str2date(this.startTime);
        }
        return null;
    }
    public Date convertEndTime() throws ParseException {
        if(this.endTime!=null){
            return DateUtil.str2date(this.endTime);
        }
        return null;
    }
}
